<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" href="http://www.petercorke.com/RVC/common/toolboxhelp.css">
    <title>M-File Help: imatch</title>
  </head>
  <body>
  <table border="0" cellspacing="0" width="100%">
    <tr class="subheader">
      <td class="headertitle">M-File Help: imatch</td>
      <td class="subheader-left"><a href="matlab:open imatch">View code for imatch</a></td>
    </tr>
  </table>
<h1>imatch</h1><p><span class="helptopic">Template matching</span></p><strong>xm</strong> = <span style="color:red>imatch</span>(<strong>im1</strong>, <strong>im2</strong>, <strong>x</strong>, <strong>y</strong>, <strong>H</strong>, <strong>s</strong>) is the matching subimage of <strong>im1</strong> (template)
within the image <strong>im2</strong>.  The template in <strong>im1</strong> is centred at (<strong>x</strong>,<strong>y</strong>) and its
half-width is <strong>H</strong>.

The template is searched for within <strong>im2</strong> inside a rectangular region, centred
at (<strong>x</strong>,<strong>y</strong>) and of size <strong>s</strong>.  If <strong>s</strong> is a scalar the search region is [-<strong>s</strong>, <strong>s</strong>, -<strong>s</strong>, <strong>s</strong>] % relative to (<strong>x</strong>,<strong>y</strong>).  More generally <strong>s</strong> is a 4-vector <strong>s</strong>=[xmin, xmax, ymin, ymax]
relative to (<strong>x</strong>,<strong>y</strong>).

The return value is <strong>xm</strong>=[DX,DY,CC] where (DX,DY) are the x- and y-offsets
relative to (<strong>x</strong>,<strong>y</strong>) and CC is the similarity score (zero-mean normalized cross
correlation) for the best match in the search region.

[<strong>xm</strong>,<strong>score</strong>] = <span style="color:red>imatch</span>(<strong>im1</strong>, <strong>im2</strong>, <strong>x</strong>, <strong>y</strong>, <strong>w2</strong>, <strong>s</strong>) works as above but also
returns a matrix of matching score values for each template position tested.
The rows correspond to horizontal positions of the template, and columns the
vertical position.

<h2>Notes</h2>
<ul>
  <li>Useful for tracking a template in an image sequence.</li>
  <li>Is a MEX file.</li>
  <li>IM1 and IM2 must be the same size.</li>
  <li>ZNCC matching is used, a perfect match score is 1.0</li>
</ul>
<h2>See also</h2>
<p>
<a href="matlab:doc isimilarity">isimilarity</a></p>
<hr>

<table border="0" width="100%" cellpadding="0" cellspacing="0">
  <tr class="subheader" valign="top"><td>&nbsp;</td></tr></table>
<p class="copy">&copy; 1990-2011 Peter Corke.</p>
</body></html>